#include "process.h"
#include <string.h>
#include<unistd.h>

#define NUM 101
#define STY '='

void FlushProcess(double total,double cur)
{

    char buffer[NUM];
    memset(buffer,0,sizeof(buffer));
    const char *yy ="|/-\\";
    int len = strlen(yy);

    static int cnt =0;

    int num = (int)(cur*100/total);
    for(int i=0;i<num;i++)
    {
        buffer[i] = STY;
    }
    double rate = cur/total;

    cnt%=len;
    printf("[%-100s][%.1f%%][%c]\r",buffer,rate*100,yy[cnt]);
    cnt++;
    fflush(stdout);
}


void process_v1()
{
    char buffer[NUM];
    memset(buffer,0,sizeof(buffer));
    const char *yy ="|/-\\";
    int cnt=0,len = strlen(yy);
    while(cnt<=100)
    {
        printf("[%-100s][%d%%][%c]\r",buffer,cnt,yy[cnt%len]);
        fflush(stdout);
        buffer[cnt] = STY;
        cnt++;
        usleep(50000);
    }
    printf("\n");
}
